import Vue from "vue";
import VueRouter from "vue-router";
import layout from "@/layout";
import NProgress from "nprogress";

Vue.use(VueRouter);

const routes = [
  {
    path: "/home",
    name: "home",
    component: layout,
    children: [
      {
        name: "home",
        path: "/home",
        title: "部分实例",
        meta: {
          keepalive: true,
        },
        component: () => import("@/views/home/index.vue"),
      },
    ],
  },
  {
    path: "/detail",
    component: layout,
    meta: {
      hidden:true,
    },
    children: [
      {
        name: "detail",
        path: "/detail",
        title: "详情",
        meta: {
          hidden:true,
          keepalive: true,
        },
        component: () => import("@/views/echartsDetail/index"),
      },
    ],
  },
  {
    path: "/file",
    component: layout,
    children: [
      {
        name: "file",
        path: "/file",
        title: "api文档",
        meta: {
          keepalive: true,
        },
        component: () => import("@/views/file/index"),
      },
    ],
  },
  {
    path: "/about",
    name: "about",
    title: "关于",
    component: layout,
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    children: [
      {
        path: "/about/h1",
        title: "关于我们1",
        name: "anbout1",
        component: () =>
          import(/* webpackChunkName: "about" */ "../views/HomeView.vue"),
      },
      {
        path: "/about/h2",
        title: "关于我们2",
        name: "anbout2",
        component: () =>
          import(/* webpackChunkName: "about" */ "../views/AboutView"),
      },
    ],
  },
  {
    path: "/about2",
    name: "about3",
    title: "关于",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/AboutView"),
  },
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach((to, form, next) => {
  NProgress.start();
  next();
});
router.afterEach(() => {
  // 在即将进入新的页面组件前，关闭掉进度条
  NProgress.done();
});
export default router;
